{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 07 数据归一化处理"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 最值归一化 Normalization"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "x = np.random.randint(0, 100, 100) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([28, 36, 30, 48, 60, 24, 46, 47, 94, 90, 58, 78, 89, 12, 38,  6, 95,\n",
       "       58, 16, 61, 65, 60, 85, 82, 82, 74, 17, 47, 15, 19, 30, 34, 29, 22,\n",
       "       32, 81, 75, 68, 15, 10, 97, 75, 49, 50, 32, 88, 64, 43, 82, 94,  1,\n",
       "       28, 60, 90, 94, 83, 29, 32,  4, 63,  5, 72, 50, 22, 90, 97, 31, 92,\n",
       "       76, 19, 22, 91, 84, 85, 75, 69, 38, 56,  0, 77, 57, 57,  2, 12, 36,\n",
       "       11, 88, 24, 59, 99, 85, 69, 44, 61, 64, 12, 69, 76, 15, 66])"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 0.28282828,  0.36363636,  0.3030303 ,  0.48484848,  0.60606061,\n",
       "        0.24242424,  0.46464646,  0.47474747,  0.94949495,  0.90909091,\n",
       "        0.58585859,  0.78787879,  0.8989899 ,  0.12121212,  0.38383838,\n",
       "        0.06060606,  0.95959596,  0.58585859,  0.16161616,  0.61616162,\n",
       "        0.65656566,  0.60606061,  0.85858586,  0.82828283,  0.82828283,\n",
       "        0.74747475,  0.17171717,  0.47474747,  0.15151515,  0.19191919,\n",
       "        0.3030303 ,  0.34343434,  0.29292929,  0.22222222,  0.32323232,\n",
       "        0.81818182,  0.75757576,  0.68686869,  0.15151515,  0.1010101 ,\n",
       "        0.97979798,  0.75757576,  0.49494949,  0.50505051,  0.32323232,\n",
       "        0.88888889,  0.64646465,  0.43434343,  0.82828283,  0.94949495,\n",
       "        0.01010101,  0.28282828,  0.60606061,  0.90909091,  0.94949495,\n",
       "        0.83838384,  0.29292929,  0.32323232,  0.04040404,  0.63636364,\n",
       "        0.05050505,  0.72727273,  0.50505051,  0.22222222,  0.90909091,\n",
       "        0.97979798,  0.31313131,  0.92929293,  0.76767677,  0.19191919,\n",
       "        0.22222222,  0.91919192,  0.84848485,  0.85858586,  0.75757576,\n",
       "        0.6969697 ,  0.38383838,  0.56565657,  0.        ,  0.77777778,\n",
       "        0.57575758,  0.57575758,  0.02020202,  0.12121212,  0.36363636,\n",
       "        0.11111111,  0.88888889,  0.24242424,  0.5959596 ,  1.        ,\n",
       "        0.85858586,  0.6969697 ,  0.44444444,  0.61616162,  0.64646465,\n",
       "        0.12121212,  0.6969697 ,  0.76767677,  0.15151515,  0.66666667])"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(x - np.min(x)) / (np.max(x) - np.min(x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "X = np.random.randint(0, 100, (50, 2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "X = np.array(X, dtype=float)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[  1.,   1.],\n",
       "       [ 89.,  95.],\n",
       "       [ 40.,   6.],\n",
       "       [ 24.,  50.],\n",
       "       [ 93.,  32.],\n",
       "       [ 46.,  74.],\n",
       "       [ 50.,  74.],\n",
       "       [ 89.,  25.],\n",
       "       [ 39.,  51.],\n",
       "       [ 54.,  79.]])"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X[:10,:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "X[:,0] = (X[:,0] - np.min(X[:,0])) / (np.max(X[:,0]) - np.min(X[:,0]))\n",
    "X[:,1] = (X[:,1] - np.min(X[:,1])) / (np.max(X[:,1]) - np.min(X[:,1]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0.01010101,  0.        ],\n",
       "       [ 0.8989899 ,  0.96907216],\n",
       "       [ 0.4040404 ,  0.05154639],\n",
       "       [ 0.24242424,  0.50515464],\n",
       "       [ 0.93939394,  0.31958763],\n",
       "       [ 0.46464646,  0.75257732],\n",
       "       [ 0.50505051,  0.75257732],\n",
       "       [ 0.8989899 ,  0.24742268],\n",
       "       [ 0.39393939,  0.51546392],\n",
       "       [ 0.54545455,  0.80412371]])"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X[:10,:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAD8CAYAAACMwORRAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAFThJREFUeJzt3VGMXFd9x/Hvr5tEWgRlEV4QXse1WxlDpJAmGZKojtqk\niMaOVDkEHgKIqBGSFZUgnqKYPsADDzHKC0UJWFZkRVEr/NBExjQGU8mFVAouXsshjpMabY2IPUGK\nA5hKYCk4+fdhx/JkPOu5s3vv3HvO/X0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t8twBeB\np4DXJtm4ChQ53s8AT0fEKwARkfIxFzneAN4lScA7WQz385NtZjki4lkW27+UieVUKuE+B5zqe326\nt23cfVIx7rF8nsXeQIpGHqukOeATwLcn2K6qFPluPwi8R9KPJB2RdO/EWle+Isf7KPBh4FXgGPCl\niHhrMs2buInlVKHH7FlzSbqdxXC/te62VOgbwEMR8dZi5y57VwA3Ah8DpoGfSDoUET+vt1mVuQN4\nHvhb4C+A/5D0XxHxf/U2K22phHsXuLrv9ZretnH3SUWhY5H0EeBxYEtE/HpCbStbkWPtAHt6wb4K\nuFPS+YjYO5kmlqrI8Z4Gfh0Rvwd+L+lZ4DogxXAvcrz3ATticVB6QdIvgA8BP51MEydqYjmVyrDM\nYWCDpPWSrgLuAfYN7LMPuLd3N/oW4HcR8atJN7QkI49X0lrgaeBziffoRh5rRKyPiHURsQ74N+Af\nEw12KPa3/F3gVklXSHoHcDPw8oTbWZYix/sKi1cpSHo/sBE4OdFWTs7EciqJnntEnJf0AHCAxbvv\nuyPiuKT7e+/vZLGK4k5gAfgDi72BJBU83q8A7wW+1evRno8EF2EqeKzZKHK8EfGypB8ALwBvAY9H\nxNDSuqYr+P1+DXhC0jEWq0geiogkV4uU9B3gNmCVpNPAV4ErYfI55RmqZmYZSmVYxszMxuBwNzPL\nkMPdzCxDDnczsww53M3MMuRwNzPLkMPdzCxDDnczswz9P9o+MBFBlvikAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x10f902198>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.scatter(X[:,0], X[:,1])\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.52363636363636368"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.mean(X[:,0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.29233209762268586"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.std(X[:,0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.48927835051546387"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.mean(X[:,1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.27176798604689073"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.std(X[:,1])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 均值方差归一化 Standardization"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "X2 = np.random.randint(0, 100, (50, 2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "X2 = np.array(X2, dtype=float)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 97.,  37.],\n",
       "       [ 60.,  75.],\n",
       "       [ 51.,  41.],\n",
       "       [ 53.,  53.],\n",
       "       [ 96.,  51.],\n",
       "       [ 47.,  94.],\n",
       "       [ 97.,  69.],\n",
       "       [ 30.,  65.],\n",
       "       [ 48.,  36.],\n",
       "       [ 26.,  14.]])"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X2[:10,:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "X2[:,0] = (X2[:,0] - np.mean(X2[:,0])) / np.std(X2[:,0])\n",
    "X2[:,1] = (X2[:,1] - np.mean(X2[:,1])) / np.std(X2[:,1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYAAAAD8CAYAAAB+UHOxAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAFslJREFUeJzt3W2MXFd9x/HfD5NIK4S0UJsk3mQbV42sBozqdOSGGNEA\ngTwQ1caFKukLqIpkBcjLpl0UiUq8sWmkvgACwVRRQWoTRSrZWNjBjbFQWlRo1jhPJriYkCiehNgB\nORTVKiT8+2Kv8diZ2Z2de2fuufd8P9Jq5+F4zn/vjOd/nu65jggBAPLzuroDAADUgwQAAJkiAQBA\npkgAAJApEgAAZIoEAACZIgEAQKZIAACQKRIAAGTq9XUHsJTVq1fHpZdeWncYANAYBw8efCki1gxT\nNukEcOmll2phYaHuMACgMWw/O2xZhoAAIFMkAADIFAkAADJFAgCATJEAACBTJAAAyFTSy0BRv/lD\nXd2x74ieP3lKa6endNu167V140zdYQGoAAkAA80f6upTX39Cp379qiSpe/KUPvX1JySJJAC0AAkA\nA92x78hvv/xPO/XrV3XHviOVJ4C6exp111+XXP9uLCIBYKDnT55a0eOjqrunUXf9dcn178YZTAJj\noLXTUyt6fFRL9TQmoe7665Lr313W/KGuNu88oHVze7R55wHNH+rWHdLISAAY6LZr12vqvFVnPTZ1\n3irddu36SuuZVE8j1frrkuvfXcbpXlP35CmFzvSampoESAAYaOvGGe3YtkEz01OypJnpKe3YtqHy\n4YFJ9TRSrb8uuf7dZbSt10QCwJK2bpzRd+beo5/s/IC+M/eesYwNT6qnkWr9dcn17y6jbb2mSiaB\nbd8t6UZJxyPibX2ev1rSA5J+Ujz09Yj4TBV1o/lOJ5W6VqPUXX9dUv67U12dtHZ6St0+X/ZN7TU5\nIsq/iP0uSb+U9LUlEs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XYXqUrl2F4QES8Ut38q6YIB5eo6rsMcp1SO5bBxXFUMqTxo+62TCW0kqRzXYSV7XGu5Itik9xcq\na5h4h/DOiOjafosWT5z7YdF6qFRFsU7EUrH23omIsD1oudpEjmsGvi9pNiJ+afsGSfOSLqs5pjZI\n+rjWkgBiwvsLlbVcvEO+Rrf4fdz2/Vrsllf+RVVBrBM7tkvFavtF2xdFxAtF9/74gNeYyHHtY5jj\nNNHP6RKWjSMiftFze6/tL9peHREp7ruTynFdVurHNbkhoGJ/ob+R9KcR8b8Dij0i6TLb62yfL+km\nSbsnFeNK2X6D7Teevq3Fie6+qwYSkMqx3S3po8Xtj0p6Te+l5uM6zHHaLekjxaqVKyW93DOsNUnL\nxmr7Qtsubm/S4nfDzyYe6XBSOa7LSv641j0Lfe6PpKNaHN97tPi5q3h8raS9PeVu0OImcz/W4vBG\nXfF+UItjkP8n6UVJ+86NV4urLx4rfg7XFe8wsaZybCX9jqRvSfqRpP2S3pzace13nCTdIumW4ra1\neDW8H0t6QkusEksg1luLY/iYFhdfXFVjrPdIekHSr4vP68cSPq7LxZrMce33w5nAAJCp5IaAAACT\nQQIAgEyRAAAgUyQAAMgUCQAAMkUCAIBMkQAAIFMkAADI1P8D97GTPfyWClwAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x10f87ae48>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.scatter(X2[:,0], X2[:,1])\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-1.1990408665951691e-16"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.mean(X2[:,0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.0"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.std(X2[:,0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-1.1546319456101628e-16"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.mean(X2[:,1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.99999999999999989"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.std(X2[:,1])"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
